//@author A0101712B
#include "CLR-UI.h"

using namespace Twentyfifth;
using namespace Poco::Net;
using namespace Poco;
using namespace std;

int main(int argc, char *argv[]) {
	try {
		SharedPtr<PrivateKeyPassphraseHandler> pConsoleHandler = new KeyConsoleHandler(true);
		SharedPtr<InvalidCertificateHandler> pInvalidCertHandler = new ConsoleCertificateHandler(true);
		Context::Ptr pContext = new Context(Context::CLIENT_USE, "", "", "", Context::VERIFY_NONE, 9, true, "ALL:!ADH:!LOW:!EXP:!MD5:@STRENGTH");
		SSLManager::instance().initializeClient(pConsoleHandler, pInvalidCertHandler, pContext);
	}
	catch (Exception&) {}
	TwentyfifthUI UIComponent;
	Logic LogicComponent;
	string feedback;
	Status statusFeedback;
	string userInput;

	UIComponent.printWelcomeMessage();
	while (statusFeedback.code != Status::EXIT) {

		UIComponent.printUserPrompt();

		getline(cin, userInput);
		try {
			statusFeedback = LogicComponent.executeProgram(userInput);
		}
		catch (Poco::Exception &e) {
			cerr << e.displayText() << endl;
		}
		catch (exception &e) {
			cerr << e.what() << endl;
		}
		//this function will update feedback with status code (which has been translated into string)
		feedback = statusFeedback.desc;
		//this will print out the feedback message.

		//this will print out the tasks. If got task, it will print, if not, it will do nothing.
		//for eg, for add, it will do nothing. For view, it will print out a vector task.
		//but since our view function is not working right now, so.... :(
		UIComponent.printVectorMessage(statusFeedback.tasks);
		UIComponent.printMessage(feedback);
	}
	return 0;
}